package com.ssh.test;

public class MyThread extends Thread {
	//静态对象锁住所有线程
	private static Object o = new Object();
	private static int count = 0;
	private char ID;
	private int id;
	private int num = 0;

	public MyThread(int id, char ID) {
		this.id = id;
		this.ID = ID;
	}

	public void run() {
		synchronized (o) {
			while (num < 10) {
				if (count % 3 == id) {
					System.out.print(ID);
					if(id==2){
						System.out.println();
					}
					++count;
					++num;
					o.notifyAll();
				} else {
					try {
						o.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	public static void main(String[] args) {
		(new MyThread(0, 'A')).start();
		(new MyThread(1, 'B')).start();
		(new MyThread(2, 'C')).start();
	}
}